<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #root {
        width: 100vw;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        gap: 20px;
        flex-wrap: wrap;
      }
    </style>
    <script src="../js/vue.js" type="text/javascript"></script>
  </head>
  <body>
    <!-- 
      v-for指令：
      1.用于展示列表数据
      2.语法：v-for="(item, index) in xxx" :key="yyy"
        其中，xxx是数组，item是数组中的元素，index是索引
        yyy是每个元素的唯一标识，一般使用item中的id值
      3.可遍历：数组、对象、字符串、指定次数
     -->

    <div id="root">
      <h2>人员信息</h2>
      <input type="text" v-model="keyWord" placeholder="请输入名字" />
      <ul>
        <li v-for="(p,index) in showPersons" :key="p.id">
          {{index}}-{{ p.name }}-{{ p.age }}-{{ p.sex }}
        </li>
      </ul>
    </div>

    <script type="text/javascript">
      new Vue({
        el: "#root",
        data: {
          keyWord: "",
          persons: [
            {
              id: 1,
              name: "马冬梅",
              age: 30,
              sex: "女",
            },
            {
              id: 2,
              name: "周冬雨",
              age: 29,
              sex: "女",
            },
            {
              id: 3,
              name: "周杰伦",
              age: 45,
              sex: "男",
            },
            {
              id: 4,
              name: "林俊杰",
              age: 36,
              sex: "男",
            },
          ],
        },
        computed: {
          showPersons() {
            return this.persons.filter((item) =>
              item.name.includes(this.keyWord)
            );
          },
        },
      });
    </script>
  </body>
</html>
